﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Authentificated.master" AutoEventWireup="true" CodeFile="UserDetails.aspx.cs" Inherits="UserManagement_UserDetails" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MCPH_Auth" Runat="Server">
    <h1>Користувач</h1>
    
    <asp:ObjectDataSource ID="odsUser" runat="server"
        TypeName="PM.BusinessLayer.UserController"
        DataObjectTypeName="PM.Entities.User"
        SelectMethod="GetUser"
        DeleteMethod="Delete"
        UpdateMethod="Update"
        InsertMethod="Insert">
        <SelectParameters>
            <asp:QueryStringParameter QueryStringField="UserID" Name="id" />
        </SelectParameters>                
    
    </asp:ObjectDataSource>
    
    <asp:ObjectDataSource ID="odsRole" runat="server" 
        DataObjectTypeName="PM.Entities.UserInRole"
        TypeName="PM.BusinessLayer.UserController"
        SelectMethod="GetMissingRoles">
        <SelectParameters>
            <asp:QueryStringParameter QueryStringField="UserID" Name="userId" />
        </SelectParameters>
    </asp:ObjectDataSource>
    
    <asp:ObjectDataSource ID="odsUserRole" runat="server"
        DataObjectTypeName="PM.Entities.UserInRole"
        TypeName="PM.BusinessLayer.UserController"
        SelectMethod="GetUserInRoles"
        DeleteMethod="DisableRole">
    
        <SelectParameters>
            <asp:QueryStringParameter QueryStringField="UserID" Name="userId" />
        </SelectParameters>
    </asp:ObjectDataSource>
    
    <asp:FormView ID="fmvUser" runat="server" DataSourceID="odsUser" 
        DataKeyNames="UserID">
        <ItemTemplate>
            <table cellspacing="10" style="text-align:left;">
                <tr>
                    <th style="width:150px;">Код</th>
                    <td><%# Eval("UserID") %></td>
                </tr>
                <tr>
                    <th>Логін</th>
                    <td><%# Eval("Login")%></td>
                </tr>                   
                <tr>
                    <th>П.І.Б.</th>
                    <td><%# Eval("FullName") %></td>
                </tr>
                <tr>
                    <th>Адреса</th>
                    <td><%# Eval("Address")%></td>
                </tr>
                <tr>
                    <th>Дата народження</th>
                    <td><%# Eval("Birth")%></td>
                </tr>
                <tr>
                    <th>E-mail</th>
                    <td><%# Eval("Email")%><br /><br /></td>
                </tr>                
                <tr>
                    <td colspan="2">
                        <asp:Button ID="btnRetuntToUsers_View" runat="server" Text="Перелік користувачів" PostBackUrl="~/UserManagement/Users.aspx" />
                        &nbsp;
                        <asp:Button ID="btnEditUser_View" runat="server" Text="Редагувати" CommandName="Edit" />
                        &nbsp;
                        <asp:Button ID="btnDeleteUser" runat="server" Text="Видалити" OnClick="btnDeleteUser_Click" />
                        &nbsp;
                        <%--<asp:Button ID="btnRegeneratePassword" runat="server" Text="Перегенерувати пароль" OnClick="btnRegeneratePassword_Click" />--%>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
        <EditItemTemplate>
            <table cellspacing="10" style="text-align:left;">
                <tr>
                    <th>Код</th>
                    <td><%# Eval("UserID") %></td>
                </tr>
                <tr>
                    <th>Логін</th>
                    <td><asp:Label ID="lblLogin" runat="server" Text='<%# Bind("Login")%>' /></td>                    
                </tr>                    
                <tr>
                    <th>П.І.Б.</th>
                    <td><asp:TextBox ID="txtFullName_Edit" runat="server" Width="350px" Text='<%# Bind("FullName") %>' /> </td>
                </tr>
                <tr>
                    <th>Адреса</th>
                    <td><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Address") %>' Width="350px" /> </td>
                </tr>
                <tr>
                    <th>Дата народження</th>
                    <td><asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Birth") %>' Width="350px" /> </td>
                </tr>
                <tr>
                    <th>E-mail</th>
                    <td><asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Email") %>' Width="350px" /> </td>
                </tr>                
                <tr>
                    <th>Пароль</th>
                    <td><asp:TextBox ID="tbPass1" TextMode="Password" runat="server" Text='<%# Bind("Password") %>' /> </td>
                </tr>
                <tr>
                    <th>Підтвердження</th>
                    <td><asp:TextBox ID="tbPass2" TextMode="Password" runat="server" /> 
                        <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Паролі не співпадають"
                        ControlToValidate="tbPass2" ControlToCompare="tbPass1" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button ID="btnUpdateUser_Edit" runat="server" Text="Зберегти" CommandName="Update" />
                        &nbsp;
                        <asp:Button ID="btnCancelUpdate_Edit" runat="server" Text="Скасувати" CommandName="Cancel" />
                    </td>
                </tr>
            </table>        
        </EditItemTemplate>
        <InsertItemTemplate>
            <table cellspacing="10" style="text-align:left;">
               
                <tr>
                    <th>Логін</th>
                    <td><asp:TextBox ID="txtLoging_Insert" runat="server" Text='<%# Bind("Login") %>' /> </td>
                </tr>                    
                <tr>
                    <th>П.І.Б.</th>
                    <td><asp:TextBox ID="txtName1_Insert" runat="server" Text='<%# Bind("FullName") %>' /> </td>
                </tr>
                <tr>
                    <th>Адреса</th>
                    <td><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Address") %>' /> </td>
                </tr>
                <tr>
                    <th>Дата народження</th>
                    <td><asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Birth") %>' /> </td>
                </tr>
                <tr>
                    <th>E-mail</th>
                    <td><asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Email") %>' /> </td>
                </tr>
                <tr>
                    <th>Пароль</th>
                    <td><asp:TextBox ID="tbPass1" TextMode="Password" runat="server" Text='<%# Bind("Password") %>' /> </td>
                </tr>
                <tr>
                    <th>Підтвердження</th>
                    <td><asp:TextBox ID="tbPass2" TextMode="Password" runat="server" /> 
                        <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Паролі не співпадають"
                        ControlToValidate="tbPass2" ControlToCompare="tbPass1" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbPass1" runat="server" ErrorMessage="Поле пароль не може бути пустим!" />
                    </td>
                </tr>
                
                <tr>
                    <td colspan="2">
                        <asp:Button ID="btnInsert_Insert" runat="server" Text="Зберегти" OnClick="btnInsert_Insert_Click" />
                        &nbsp;
                        <asp:Button ID="btnCancelInsert_Insert" runat="server" Text="Скасувати" PostBackUrl="~/UserManagement/Users.aspx" />
                    </td>
                </tr>
            </table>        
        </InsertItemTemplate>
        
    </asp:FormView>
<hr /><br />
    <table>
    <tr>
        <td>Ролі:</td>
    </tr>
    <tr>
        <td valign="top">
            <table>
                <tr>
                    <td colspan="2" style="width:180px;">
                        <asp:GridView ID="grvUserRole" runat="server" 
        DataSourceID="odsUserRole" CssClass="UserGridView"
        AutoGenerateColumns="false"
        DataKeyNames="UIRID" onrowdeleted="grvUserRole_RowDeleted">
        <EmptyDataTemplate>
            Не вказано жодної ролі
        </EmptyDataTemplate>
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lblUserID" runat="server" Text='<%# Bind("UserID") %>' Visible="false" /></ItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Роль">
                <ItemTemplate>
                    <asp:Label ID="lblRoleName" runat="server" Text='<%# Bind("Role.RoleUA") %>' /></ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Дія">
                <ItemTemplate>
                    <asp:LinkButton ID="lbtDeleteRole" runat="server" CommandName="Delete" Text="Видалити" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView></td></tr>
                    <tr><td>
                        <asp:DropDownList ID="ddlMissingRoles" runat="server" DataSourceID="odsRole" DataValueField="RoleID" DataTextField="RoleUA" /></td>
                    <td>
                        <asp:Button ID="btnAddToRole" runat="server" Text="Додати" OnClick="btnAddToRole_Click" /></td></tr>
            </table></td>
    </tr>
</table>        
    <br />
    
    
    
    
    <br /><br /><br />
</asp:Content>

